package com.base.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.base.po.voip.UsersRebate;
import com.base.service.UsersRebateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.service.LogsService;
import com.base.service.UsersService;
import com.base.utils.IP;

/**
 * 账户配置信息 修改
 * 
 * @author f 优化日期：10-11
 *
 */
@Controller
@RequestMapping("/admin")
public class UsersRebateUpdateController {

	@Autowired
	private LogsService logsService; // 日志Service
	@Autowired
	private UsersService usersService; // 账户信息Service
	@Autowired
	private UsersRebateService usersRebateService;

	// 账户信息 修改
	@RequestMapping(value = "/usersrebate_do_update", method = RequestMethod.POST)
	public @ResponseBody int doUpdate(HttpServletRequest request, UsersRebate usersRebate) {
		HttpSession session = request.getSession(false); // 获取session
		if (session == null) {
			return -1;
		}
		Object obj_id = session.getAttribute("adminUserId"); // 登录ID
		Object obj_name = session.getAttribute("userNick"); // 登录名称
		if (obj_id == null || obj_name == null) {
			return -1;
		}

		logsService.insert(CommContent.TYPE_UPDATE, CommContent.LOGS_UPDATE + "账户配置信息", (String) obj_name, true,
				IP.getIpAddr(request));

		return usersRebateService.updateByPrimaryKeySelective(usersRebate); // 修改
	}
}
